package com.feng.spring5.test;

import com.feng.spring5.config.SpringConfig;
import com.feng.spring5.dao.UserDaoImpl;
import com.feng.spring5.service.UserService;
import org.junit.jupiter.api.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class bean5 {
    @Test
    public void test(){
        ApplicationContext context = new ClassPathXmlApplicationContext("bean5.xml");
        UserService userService = context.getBean( UserService.class);
        //UserDaoImpl userDao = context.getBean(UserDaoImpl.class);
        //System.out.println(userDao);
        System.out.println(userService);
        userService.add();
    }

    @Test
    public void testConfig(){
        //加載配置類（完全注解類（沒有xml文件））
        ApplicationContext context = new AnnotationConfigApplicationContext(SpringConfig.class);
        UserService userService = context.getBean( UserService.class);
        //UserDaoImpl userDao = context.getBean(UserDaoImpl.class);
        //System.out.println(userDao);
        System.out.println(userService);
        userService.add();
    }
}
